import ReactCurrentDispatcher from './ReactCurrentDispatcher';

function resolveDispatcher() {
    return ReactCurrentDispatcher.current;
};

/**
 * 描述
 * @date 2023-03-22
 * @param {any} reducer 处理函数，用于根据来状态和动作计算新状态
 * @param {any} initialArg 初始状态
 * @returns {any}
 */
export function useReducer(reducer, initialArg) {
    const dispatcher = resolveDispatcher();
    return dispatcher.useReducer(reducer, initialArg);
}

export function useState(initialArg) {
    const dispatcher = resolveDispatcher();
    return dispatcher.useState(initialArg);
}

export function useEffect(create, deps) {
    const dispatcher = resolveDispatcher();
    return dispatcher.useEffect(create, deps);
}

export function useLayoutEffect(create, deps) {
    const dispatcher = resolveDispatcher();
    return dispatcher.useLayoutEffect(create, deps);
}

export function useRef(initialState) {
    const dispatcher = resolveDispatcher();
    return dispatcher.useRef(initialState);
}